// pages/user_end/classification/classification.js
const app = getApp();
const request = require('../../../utils/request.js');
const url = require('../../../utils/url.js');
const cookie = require('../../../utils/cookie.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bg: '#08B266',
    nindex: 0,
    banner: [],
    list: [],
    category: [],
    keyword: '',
	cityName:'',
	cityId:0
	
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
	  var that = this;
	  var cityName =wx.getStorageSync('cityName');
	    that.setData({
	      cityName:cityName
	    })
    this.getBanner();
    this.getList();
	this.getCategory();
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  clickBanner(e) {
    console.log(e);
    var jump = e.currentTarget.dataset.jump;
    var type = e.currentTarget.dataset.type;
    var id = e.currentTarget.dataset.id;
    if(jump=='1'){
      if(type=='1'){
        wx.navigateTo({
          url:"../article/article?id="+id
        })
      }else if(type=='2'){
        wx.navigateTo({
          url:"../server_info/server_info?id="+id
        })						
      }
    }
  },
  getBanner() {
    var that = this;
    let param = {
      scoure: 'wxapp',
      location: 2
    }
    wx.showNavigationBarLoading(); //在当前页面显示导航条加载动画
    request.request(url.getbannerlist, param, url.REQUEST_METHOD_GET).then((res) => {
      wx.hideNavigationBarLoading(); //在当前页面隐藏导航条加载动画
      if(res.data.code==1){
        that.setData({
          banner:res.data.data
        })
      }
    })  			
  },
  doSearch() {
    var that = this;
    wx.navigateTo({
      url: '../server_list/server_list?id=0&type=1&key=' + that.data.keyword
    })
  },
  gotoServiceInfo(e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../server_info/server_info?id=' + id
    })
  },
  chooseNav(e) {
    var that = this;
    let id = e.currentTarget.dataset.id;
    that.setData({
      nindex:e.currentTarget.dataset.navindex
    })
    this.getCategory(id);
  },
  getList() {
    var that = this;
    let param = {
      scoure: 'wxapp',
	  cityName:that.data.cityName
    }
    request.request(url.getcategory, param, url.REQUEST_METHOD_GET).then((res) => {
      that.setData({
        list:res.data.data
      })
      if (that.data.list.length > 0) {
        that.getCategory(that.data.list[0].id);
      }
    })
  },
  getCategory(id) {
    var that = this;
    let param = {
      scoure: 'wxapp',
      id: id,
	  cityName:that.data.cityName
    }
    wx.showNavigationBarLoading(); //在当前页面显示导航条加载动画
    request.request(url.getservicesecond, param, url.REQUEST_METHOD_GET).then((res) => {
      wx.hideNavigationBarLoading(); //在当前页面隐藏导航条加载动画
      if(res.data.code==1){
        that.setData({
          category:res.data.data
        })
      }
    })  	
  },
  changekeyword(e){
     var key =e.detail.value;
     this.setData({
      keyword:key
     })
  }
})